<?php
/**
 * Created by PhpStorm.
 * User: meng
 * Date: 2021/7/6
 * Time: 9:43 下午
 */

namespace app\admin\controller;


use app\admin\model\AdminMenuModel;
use app\admin\validator\AdminMenuValidator;

class Menus extends AdminBaseController
{
    public function read ($id) {
        $data = AdminMenuModel::findMenu($id);
        $this->writeJson($data);
    }

    public function save () {
        $params = $this->request->param();
        (new AdminMenuValidator())->goCheck($params, 'create');
        AdminMenuModel::createMenu($params);
        $this->writeJson();
    }

    public function delete ($id) {
        AdminMenuModel::deleteMenu($id);
        $this->writeJson();
    }

    public function update ($id) {
        $params = $this->request->param();
        (new AdminMenuValidator())->goCheck($params, 'update');
        AdminMenuModel::updateMenu($id, $params);
        $this->writeJson();
    }

    public function tree () {
        $data = AdminMenuModel::menuTree();
        $this->writeJson($data);
    }
}
